<?php
namespace Account\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Authentication\Adapter\DbTable as DbTableAuthAdapter;
use Account\Form\CreateAccount;

class CreateController extends AbstractActionController
{
		
	
	public function indexAction()
	{
		$form = new CreateForm();
		$viewModel = new ViewModel(array('form' =>
				$form));
				return $viewModel;
	}
	public function fooAction()
	{
		return array();
	}
/*
	public function viewAction()
	{
		$dbAdapter = $this->serviceLocator->get('Zend\Db\Adapter\Adapter');
		$dbAdapter->query('SELECT name FROM account', array(37));
	}
	*/
	
	 public function confirmAction()
    {
                $viewModel  = new ViewModel(); 
                return $viewModel; 
    }
	public function processAction()
    {
		if (!$this->request->isPost()) {
			return $this->redirect()->toRoute(NULL , 
				array( 'controller' => 'create', 
					'action' =>  'index' 
				));
	}
	  $post = $this->request->getPost();
	  $form = new CreateForm();
	  $inputFilter = new CreateFilter();
	  $form->setInputFilter($inputFilter);
	  $form->setData($post);
	  if (!$form->isValid()) {
		$model = new ViewModel(array(
		  'error' => true,
		  'form'  => $form,
		));
		$model->setTemplate('account/create/index');
		return $model;
	}
	return $this->redirect()->toRoute(NULL , array( 
		'controller' => 'create', 
		'action' =>  'confirm' 
		));
		}
	protected function createUser(array $data)
	{
		$sm = $this->getServiceLocator();
		$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
		$resultSetPrototype = new \Zend\Db\ResultSet\ResultSet();
		  $resultSetPrototype->setArrayObjectPrototype(new  
		  \Account\Model\Account);
		$tableGateway = new \Zend\Db\TableGateway\TableGateway('account', 
		$dbAdapter, null, $resultSetPrototype);
		
		$account = new Account();
		$account->exchangeArray($data);
		$accountTable = new UserTable($tableGateway);
		$accountTable->saveUser($account);
		return true;
	}
	



}
?>